1. /* scfctanh.cpp by K.Tsuru */
  2. // function ID = 9111
  3. /*********************************************************
  4. SComplex class
  5. It returns tanh(z) = {exp(2*z)-1}/{exp(2*z)+1}.
  6. Let z = x+i*y,
  7. tanh(x+i*y) = {sinh(2*x)+i*sin(2*y)}/{cosh(2*x)+cos(2*y)}.
  8. **********************************************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. #define Usectanh 0
  13. #define Useez2ctanh 0
  14. SComplex Ctanh(const SComplex& z)
  15. {
  16. if(z.IsZero()) return 0.0;
  17. #if Usectanh // 31.8 sec
  18. SComplex z2 = 2*z;
  19. SDouble den = Cosh(z2.Real())+Cos(z2.Imag());
  20. SDouble rr =Sinh(z2.Real()), ri = Sin(z2.Imag());
  21. den = 1.0/den;
  22. rr *= den; ri *= den;
  23. return SComplex(rr, ri);
  24. #elif Useez2ctanh // 16.15 sec
  25. SComplex e2z = Cexp(2.0*z), r = (e2z - 1.0)/(e2z + 1.0);
  26. return r;
  27. #else // 15.9 sec
  28. SDouble ch2x, sh2x, c2y, s2y, x2(2*Re(z)), y2(2*Im(z));
  29. Hyperbolic(x2, ch2x, sh2x); // ch2x = cosh(2x) sh2x = sinh(2x)
  30. CosSinBS(y2, c2y, s2y); // c2y = cos(2y), s2y = sin(2y);
  31. SDouble dr = 1.0/(ch2x + c2y), rr = sh2x * dr, ri = s2y * dr;
  32. return SComplex(rr, ri);
  33. #endif
  34. }

scfctanh.cpp : last modifiled at 2015/08/17 16:11:34(1,113 bytes)
created at 2017/10/06 15:21:28
The creation time of this html file is 2017/10/06 15:27:09 (Fri Oct 06 15:27:09 2017).